<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$tabs=array(
	array('op'=>'list','title'=>'经销订单列表'),
);
set_html('tabs',$tabs);
if($_RQ['op']=='list'){	
	$pindex = max(1, intval($_SESSION['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid'],'area_mid >'=>0);
	if($_RQ['mid']){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	if($_RQ['ordersn']){
		$params['ordersn like']='%'.trim($_RQ['ordersn']).'%';
		$return['params']['ordersn']=$_RQ['ordersn'];
	}
	$psize=20;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'id desc',
	);
	$list=$this->get_list('order',$parameter,$total);
	if($list){
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$item['detail']='/commission/list/ordersn='.$item['ordersn'];
			$orderid=pdo_getcolumn('jy_weishop_order',array('ordersn'=>$item['ordersn'],'uniacid'=>$_SESSION['uniacid']),'id');
			if($orderid){
				$item['isgoods']=1;
			}
			$item['areatitle']=pdo_getcolumn('jy_newcar_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$item['area_mid']),'title');
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page']=$pindex;
	$htmls=array(
		'type'=>'list',
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>true,'delall'=>true,'list'=>array(
			array('name'=>'member','title'=>'会员信息','type'=>'member'),
			array('name'=>'areatitle','title'=>'经销商','type'=>'string'),
			array('name'=>'ordersn','title'=>'订单号','type'=>'string'),
			array('name'=>'price','title'=>'支付金额','type'=>'string'),
			array('name'=>'carprice','title'=>'车价','type'=>'string'),
			array('name'=>'ispay','title'=>'支付状态','type'=>'radio','options'=>'ispay'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'time'),
		),'action'=>array(
			array('type'=>'modal','op'=>'goods','title'=>'订单商品','show'=>array('isgoods'=>1)),
			//array('type'=>'href','name'=>'detail','title'=>'明细'),
		)),
		'search'=>array(
			array('type'=>'string','width'=>15,'name'=>'ordersn','title'=>'订单号'),
			array('type'=>'choose','width'=>15,'action'=>'core/member.get_member/','name'=>'mid','title'=>'选择会员'),
		),
	);
	$return['htmls']=$htmls;
	$return['ispay']=array('未支付','已支付');
	exi($return);
}
if($_RQ['op']=='goods'){
	$item=$this->get('order',array('id'=>intval($_RQ['id']),'uniacid'=>$_SESSION['uniacid']),array('id','ordersn'));
	if(!$item){
		exi('指定订单不存在！','error');
	}
	$orderid=pdo_getcolumn('jy_weishop_order',array('ordersn'=>$item['ordersn'],'uniacid'=>$_SESSION['uniacid']),'id');
	if($orderid){
		$item=model('jy_weishop/order')->get_order($orderid);
	}
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'look',
		'desc'=>'商品清单',		
		'look'=>array(
			array('name'=>'goods','title'=>'商品信息','type'=>'array','list'=>array(
				array('type'=>'string','name'=>'goodsid','title'=>'商品ID'),
				array('type'=>'string','name'=>'title','title'=>'商品名称'),
				array('type'=>'image','name'=>'image','title'=>'商品图片'),
				array('type'=>'string','name'=>'price','title'=>'购买单价'),
				array('type'=>'string','name'=>'total','title'=>'购买数量'),
			)),
		)
	);
	exi($return);
}
if($_RQ['op'] == 'del'){
	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_newcar_order',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_newcar_order',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
			}
		}
	}
	exi('删除成功！');
}
?>